// pages/common/invite-list.js
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        page: 1,
        total: 2,
        loading: false,
        list: []
    },
    onLoad: function(options) {
        wx.showLoading({
            title: '加载中...',
        })
    },
    onShow() {
        this.loadData()
    },
    loadData() {
        let {
            page = 1, total = 2, loading = false, list = []
        } = this.data
        if (total <= list.length || loading) return
        this.setData({
            loading: true
        })
        app.http.post('rest/member/queryInviteList.do', {
            data: {
                page,
                rows: 10
            }
        }).then(res => {
            page++
            loading = false
            total = res.obj.total
            list.push(...res.obj.rows)

            this.setData({
                page,
                loading,
                total,
                list
            })

            wx.hideLoading()

        }).catch(err => {
            this.setData({
                loading: false
            })
            console.log(err)
        })
    },
    onPullDownRefresh(){
        this.setData({
            page:1,
            total:2,
            loading:false,
            list:[]
        })
        this.loadData()
    },
    onReachBottom(){
        this.loadData()
    }
})